﻿using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;

namespace PlayWCF.Hello
{
    static class CalculatorHost
    {
        private static void ManualHost()
        {
            using (ServiceHost host = new ServiceHost(typeof(CalculatorSvc)))
            {
                host.AddServiceEndpoint(typeof(ICalculator), new NetTcpBinding(), "net.tcp://localhost:7027/Calculator");

                host.Description.Behaviors.Add(new ServiceMetadataBehavior());
                Binding metaBinding = MetadataExchangeBindings.CreateMexTcpBinding();
                host.AddServiceEndpoint(typeof(IMetadataExchange), metaBinding, "net.tcp://localhost:7027/Calculator/mex");

                host.Opened += (sender, evtargs) => Console.WriteLine("Calculator Service Started.");
                host.Open();

                Console.ReadLine();
            }// using
        }

        private static void ConfigHost()
        {
        }

        public static void Run()
        {
            ManualHost();
        }// Run
    }
}
